<?php

App::uses('Controller', 'Controller');
App::uses('View', 'View');
App::uses('AutoCompleteHelper', 'View/Helper');

class AutoCompleteHelperTest extends CakeTestCase {
	public $AutoComplete = null;

	public function setUp() {
		parent::setUp();
		$Controller = new Controller();
		$View = new View($Controller);
		$this->AutoComplete = new AutoCompleteHelper($View);
	}

	public function testAjaxReszlet(){
		$this->assertContains('{afterUpdateElement : do.something}',
									 $this->AutoComplete->create(
														'osztalytol',
														'/osztalyok/search/',
															array(
																'autocompleterOptions' => '{afterUpdateElement : do.something}'
															)
															));
		
		$this->assertContains("new Ajax.Autocompleter('Osztalytol','Osztalytol_autoComplete','/osztalyok/search/', {afterUpdateElement : laksmi.bizonylat.bizonylat.getOsztalyId});",
									 $this->AutoComplete->create(
														'osztalytol',
														'/osztalyok/search/',
															array(
																'autocompleterOptions' => '{afterUpdateElement : laksmi.bizonylat.bizonylat.getOsztalyId}'
															)));

		$this->assertContains('{}',
									 $this->AutoComplete->create(
														'osztalytol',
														'/osztalyok/search/'
														)
									 );
		
		$this->assertContains('<input name="data[_Tetel][gyujto]" id="_TetelGyujto"',
									 $this->AutoComplete->create(
																	'_Tetel.gyujto',
																	'/gyujtok/search',
																	array(
																		'id' => '_TetelGyujto'
																		)
																	)
									 );
	}
	
	public function testHtmlOutput(){
		//nem data[Bizonylatok][osztalytol]-t ad vissz ahanem data[osztalytol]-t mert valójában nem a view hívja meg a tesztet
		$this->assertEquals(
								'<input name="data[osztalytol]" id="Osztalytol" autocomplete="off" type="text"/>' . "\n" .
								'<div id="Osztalytol_autoComplete" class="auto_complete" style="display:none;"></div>' . "\n" .
								'<script type="text/javascript">' . "\n" .
								'//<![CDATA[' . "\n" .
								"new Ajax.Autocompleter('Osztalytol','Osztalytol_autoComplete','/osztalyok/search/', {afterUpdateElement : laksmi.bizonylat.bizonylat.setOsztalyId});" . "\n" .
								'//]]>' . "\n" .
								'</script>',
								$this->AutoComplete->create(
														'osztalytol',
														'/osztalyok/search/',
															array(
																'autocompleterOptions' => '{afterUpdateElement : laksmi.bizonylat.bizonylat.setOsztalyId}'
															))
								  );
	}
}
?>